use std::ops::Range;

use super::error::FrameResult;

use crate::byte::*;

pub const SKIP_FRAME_MAGIC_RANGE:Range<u32> =  0x184D2A50..0x184D2A60;

#[derive(Debug)]
pub struct SkippableFrame {
    user_data:Vec<u8>,
}

impl SkippableFrame {
    pub fn serialize_into<W:ByteWrite>(&self,writer:&mut ByteWriter<W>) -> FrameResult<()> {
        let frame_size:u32 = self.user_data.len().try_into().unwrap();
        writer.write_from_u32(frame_size)?;
        writer.write_from_bytes(&self.user_data)?;
        Ok(())
    }

    pub fn deserialize_from<R:ByteRead>(reader:&mut ByteReader<R>) -> FrameResult<Self> {
        let frame_size = reader.read_to_u32()?.try_into().unwrap();
        let mut user_data = vec![0u8;frame_size];
        reader.read_to_bytes(&mut user_data)?;
        Ok(Self{ user_data })
    }
}